<?php
namespace app\sendmsg\model;

use app\BaseModel;

class CardTimelineComment extends BaseModel
{
//定义表名
    protected $name = 'longbing_card_timeline_comment';
    public function getLineComment($where,$page,$limit){
        return $this->alias( 'a' )
            ->join( 'longbing_card_user b', 'a.user_id = b.id' )
            ->where($where)
            ->order('a.create_time','desc')
            ->where('a.status',1)
            ->field(['nickName','content','avatarUrl'])
            ->paginate([ 'list_rows' =>$limit, 'page' => $page ])->each(function($item, $key){
                $item['data'] = transImages($item['data'], ['avatarUrl']);
                return $item;
            });
    }
    public function createComment($data){
        return $this->save($data);
    }
   public function getlist($where,$page,$limit){
       return  $this->alias( 'a' )
           ->join( 'longbing_card_timeline b', 'a.timeline_id = b.id' )
           ->where($where)
           ->order('a.create_time','desc')
           ->where('a.status',1)
           ->field(['a.id','a.user_id','a.timeline_id','b.title','a.content','a.create_time'])
           ->paginate([ 'list_rows' =>$limit, 'page' => $page ]);

   }
   //检测评论发表是否合法
   public function wxContentRlue($content,$access_token){
       $url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token={$access_token}";
       $tmp = [
           'url' => $url,
           'data' => [
               'content'=>urlencode($content)
           ],
       ];
       $rest = lbCurlPost($tmp['url'],urldecode(json_encode($tmp['data'])));
       $rest = json_decode($rest,true);
       return $rest;
   }
}